Overview

This post shows how to create content using R Markdown. R Markdown documents enable you to weave together plain text Markdown, R code, and interactive output such as tables and graphs in a single document.

R packages

library(readr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(DT)
library(plotly)

Data

covid_ny <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv") %>%
  filter(state == "New York")

covid_ny
## # A tibble: 424 x 5
##    date       state    fips  cases deaths
##    <date>     <chr>    <chr> <dbl>  <dbl>
##  1 2020-03-01 New York 36        1      0
##  2 2020-03-02 New York 36        1      0
##  3 2020-03-03 New York 36        2      0
##  4 2020-03-04 New York 36       11      0
##  5 2020-03-05 New York 36       22      0
##  6 2020-03-06 New York 36       44      0
##  7 2020-03-07 New York 36       89      0
##  8 2020-03-08 New York 36      106      0
##  9 2020-03-09 New York 36      142      0
## 10 2020-03-10 New York 36      173      0
## # … with 414 more rows

Tables using DT

DT::datatable(covid_ny)

Visualizations using ggplot2

covid_ny %>%
  gather(key, value, cases, deaths) %>%
  ggplot(aes(x = date, y = value)) +
  facet_wrap(~key, scales = "free_y") +
  geom_line(color = "#02718f") +
  labs(title = "Cumulative Covid-19 cases and deaths in the state of New York, USA") +
  theme_bw()

Visualizations using plotly

covid_ny %>%
  plot_ly(x = ~date, y = ~cases) %>%
  add_markers() %>%
  layout(title = "Cumulative Covid-19 cases and deaths in the state of New York, USA")